import requests
from pathlib import Path
import json
def delete_data(study_uid=None, series_description="biomind"):
    """用于删除overview
    指定study时只删除对应的满足series_description的序列
    未指定时删除所有的满足series_description的序列
    """
    orthanc_url = "http://localhost:8042"
    instances = []
    if study_uid:
        studies = json.loads(requests.get(f"{orthanc_url}/studies").text)
        for x in studies:
            param= json.loads(requests.get(f"{orthanc_url}/studies/{x}").text)
            local_studyuid = param["MainDicomTags"]["StudyInstanceUID"]
            series = param["Series"]
            if study_uid == local_studyuid:
                    instances.extend(series)
                    break
    else:
        instances = json.loads(requests.get(f"{orthanc_url}/series").text)
    instance_to_delete = []
    for x in instances:
        param= json.loads(requests.get(f"{orthanc_url}/series/{x}").text)["MainDicomTags"]["SeriesDescription"]
        if series_description.lower() in param.lower():
                instance_to_delete.append(x)
    for instance in instance_to_delete:
        print(f"delete series: {instance}")
        requests.delete(
                f"{orthanc_url}/series/{instance}",
                verify=False,
            )
#
delete_data(study_uid='1629355863.6573808.16')